package io.wit.modules.wit.controller;

import io.wit.common.utils.PageUtils;
import io.wit.common.utils.Querys;
import io.wit.common.utils.R;
import io.wit.modules.wit.entity.CashierEntity;
import io.wit.modules.wit.service.CashierService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 财务管理
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-01-16 02:39:45
 */
@RestController
@RequestMapping("cashier")
public class CashierController {
	@Autowired
	private CashierService cashierService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("cashier:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Querys query = new Querys(params);

		List<CashierEntity> cashierList = cashierService.queryList(query);
		int total = cashierService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(cashierList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{dataId}")
	@RequiresPermissions("cashier:info")
	public R info(@PathVariable("dataId") Long dataId){
		CashierEntity cashier = cashierService.queryObject(dataId);
		
		return R.ok().put("cashier", cashier);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("cashier:save")
	public R save(@RequestBody CashierEntity cashier){
		cashierService.save(cashier);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("cashier:update")
	public R update(@RequestBody CashierEntity cashier){
		cashierService.update(cashier);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("cashier:delete")
	public R delete(@RequestBody Long[] dataIds){
		cashierService.deleteBatch(dataIds);
		
		return R.ok();
	}
	
}
